package com.hqyj.bigdata.hiveproject.util;

import cn.hutool.crypto.digest.DigestUtil;
import org.springframework.stereotype.Component;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Component
public class MyUtils {


    //检查是否是合法的手机号码
    public static boolean isMobileNumber(String mobileStr) {
        Pattern p = Pattern.compile("^((13[0-9])|(15[^4])|(18[0-9])|(17[0-9])|(19[0-9])|(147))\\d{8}$");
        Matcher m = p.matcher(mobileStr);
        return m.matches();
    }

    public static boolean isEmail(String email){
        // return ReUtil.isMatch("^(\\w+([-.][A-Za-z0-9]+)*){3,18}@\\w+([-.][A-Za-z0-9]+)*\\.\\w+([-.][A-Za-z0-9]+)*$",email);
        //正则表达式匹配任何字符
        String regex = "^[\\w!#$%&'*+/=?`{|}~^-]+(?:\\.[\\w!#$%&'*+/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$";
        //编译正则表达式
        Pattern pattern = Pattern.compile(regex);
        //检索匹配器对象
        Matcher m = pattern.matcher(email);
        return m.matches();
    }

    public static String encodePassword(String password){

       return DigestUtil.bcrypt(password);
    }

    public static boolean decodePassword (String password,String encodePass){
       return  DigestUtil.bcryptCheck(password,encodePass);
    }

    public static void main(String[] args) {
        String password = "123456";
        //String encodePass = MyUtils.encodePassword(password);
        //System.out.println(encodePass);

        /*
        if(MyUtils.decodePassword("654321","$2a$10$izUE2wMM35WLOl43IeSMlOhKuIKMGVgwBPSe4p/63bU0GAtvZL/aK")) {
            System.out.println("密码校验通过");
        }else{
            System.out.println("密码校验不通过!");
        }*/

        for(int i=0;i<100;i++){
            System.out.println(MyUtils.encodePassword(password));
        }

    }
}
